//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ColorForm.h"
#include "MainForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TCF *CF;
//---------------------------------------------------------------------------
__fastcall TCF::TCF(TComponent* Owner) : TForm(Owner) {}
//---------------------------------------------------------------------------
void __fastcall TCF::FormCreate(TObject *Sender) {
	for (int i = 0; i < 10; i++) {
		colors[i].chk = new TCheckBox(SB);
		colors[i].chk->Parent = SB;
		colors[i].chk->Left = 20;
		colors[i].chk->Top = i * 30 + 21;
		colors[i].chk->Caption = "";
		colors[i].chk->Show();
		colors[i].img = new TImage(this);
		colors[i].img->Height = 20;
		colors[i].img->Width = 50;
		colors[i].img->Canvas->Brush->Color = mark_colors[i];
		colors[i].img->Canvas->Rectangle(0, 0, 50, 20);
		colors[i].img->Top = i * 30 + 20;
		colors[i].img->Left = 50;
		colors[i].img->Parent = SB;
		colors[i].img->Show();
		colors[i].edt = new TEdit(this);
		colors[i].edt->Parent = SB;
		colors[i].edt->Left = 120;
		colors[i].edt->Top = i * 30 + 20;
		colors[i].edt->Width = 170;
		colors[i].edt->Show();
	}
}
//---------------------------------------------------------------------------
void __fastcall TCF::PrBClick(TObject *Sender) {
	resourse tmp;
	res.clear();
	for (int i = 0; i < 10; i++)
		if (colors[i].chk->Checked) {
			tmp.index = i;
			tmp.desc = colors[i].edt->Text;
			res.push_back(tmp);
		}
}
//---------------------------------------------------------------------------
void __fastcall TCF::OkBClick(TObject *Sender) {
	PrBClick(this);
	Close();
}
//---------------------------------------------------------------------------
void __fastcall TCF::FormShow(TObject *Sender) {
	res0.clear();
	for (int i = 0; i < res.size(); i++) {
		res0.push_back(res[i]);
	}
}
//---------------------------------------------------------------------------
void __fastcall TCF::CanBClick(TObject *Sender) {
	for (int i = 0; i < 10; i++) {
		colors[i].chk->Checked = false;
		colors[i].edt->Text = "";
	}
	for (int i = 0; i < res0.size(); i++) {
		colors[res0[i].index].chk->Checked = true;
		colors[res0[i].index].edt->Text = res0[i].desc;
	}
	OkBClick(this);
}
//---------------------------------------------------------------------------
